package com.tencent.cloud.iov.kernel.tmpkey;

import com.tencent.cloud.iov.kernel.constant.ApiConst;
import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.kernel.service.interceptor.ExceptionTransformer;
import com.tencent.cloud.iov.kernel.service.ServiceGenerator;

import io.reactivex.Observable;

/**
 * @author vinsonhuang
 * @date 2018/5/8
 */

public class TmpKeyRepository {

    private static volatile TmpKeyRepository sInstance;

    public static TmpKeyRepository getInstance() {
        if (sInstance == null) {
            synchronized (TmpKeyRepository.class) {
                if (sInstance == null) {
                    sInstance = new TmpKeyRepository();
                }
            }
        }

        return sInstance;
    }

    private final TmpKeyService mTmpKeyService;

    private TmpKeyRepository() {
        mTmpKeyService = ServiceGenerator.createService(TmpKeyService.class, ApiConst.getBaseUrl());
    }

    public Observable<BaseResponse<TmpKeyInfo>> getAccountTmpKey(TmpKeyRequest request) {
        return mTmpKeyService.getAccountTmpKey(request)
                .compose(new ExceptionTransformer<TmpKeyInfo>());
    }

    public Observable<BaseResponse<TmpKeyInfo>> getProfileTmpKey(TmpKeyRequest request) {
        return mTmpKeyService.getProfileTmpKey(request)
                .compose(new ExceptionTransformer<TmpKeyInfo>());
    }

}
